package com.zy.baselib.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import androidx.viewbinding.ViewBinding

abstract class CommonAdapter<T, VB: ViewBinding>(
    private val layoutId: Int,
    val data: MutableList<T> = mutableListOf()
) : RecyclerView.Adapter<CommonViewHolder<VB>>() {

    override fun getItemCount() = data.size

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CommonViewHolder<VB> {
        return CommonViewHolder(LayoutInflater.from(parent.context).inflate(layoutId, parent, false))
    }

    override fun onBindViewHolder(holder: CommonViewHolder<VB>, position: Int) {
        convert(holder, position)
    }

    abstract fun convert(holder: CommonViewHolder<VB>, position: Int)

}